﻿#include "FITKMesherDriverGmshExec.h"

#include "FITKGmshExecProgramInputInfo.h"
#include "FITKGmshExecProgramDriver.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKProgramTaskManager.h"

#include "FITK_Kernel/FITKCore/FITKThreadPool.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"

#include <QFileInfo>
#include <QTimer>
#include <QDir>

namespace Gmsh
{
    FITKMesherDriverGmshExec::FITKMesherDriverGmshExec()
    {

    }

    FITKMesherDriverGmshExec::~FITKMesherDriverGmshExec()
    {

    }

    void FITKMesherDriverGmshExec::startMesher(QStringList info /*= QStringList()*/)
    {
        // TODO: 实现网格生成的启动逻辑
        Q_UNUSED(info);
        //获取划分维度、模型文件和网格文件
        QString shapeFile = this->getValueT<QString>("ShapeFile");
        QString meshFile = this->getValueT<QString>("MeshFile");
        QString geoScriptFile = this->getValueT<QString>("ScriptFile");
        GmshExe::FITKGmshExecProgramInputInfo* inputInfo = new GmshExe::FITKGmshExecProgramInputInfo;
        inputInfo->setGeoScriptFile(geoScriptFile);
        inputInfo->setMeshFile("msh", meshFile);
        AppFrame::FITKProgramTaskManeger* programTaskMgr = FITKAPP->getProgramTaskManager();
        GmshExe::FITKGmshExecProgramDriver* gmshExe = dynamic_cast<GmshExe::FITKGmshExecProgramDriver*>(programTaskMgr->createProgram(1, "FITKGmshExecProgramDriver", inputInfo));
        if (!gmshExe)return;
        gmshExe->writeConfigFile(shapeFile, geoScriptFile, meshFile);
        if (!gmshExe->isExistExeProgram())
        {
            delete gmshExe;
            return;
        }
        connect(gmshExe, SIGNAL(sig_Finish()), this, SIGNAL(mesherFinished()));
        gmshExe->start();
    }

    void FITKMesherDriverGmshExec::stopMesher(QStringList info /*= QStringList()*/)
    {
        //todo
    }

}
